package org.vaadinetherealintegration.client.example2;

import org.vaadinetherealintegration.client.ExampleInterface;

import etrl.core.Group;
import etrl.core.LightStore;
import etrl.core.Lights;
import etrl.core.Node;
import etrl.core.Viewer;
import etrl.resources.Resources;
import etrl.vecmath.Quat4f;
import etrl.vecmath.Vector3f;

public class Example2 implements ExampleInterface
{
	/**
	 * The viewer
	 */
	private Viewer _viewer;
	
	String stone_wall = "VAADIN/widgetsets/org.vaadinetherealintegration.MyWidgetSet/stone_wall.bmp";
    String floor = "VAADIN/widgetsets/org.vaadinetherealintegration.MyWidgetSet/floor.jpg";
    
	/**
	 * Constructor
	 * @param viewer the viewer ...
	 */
	public Example2(Viewer viewer)
	{
		_viewer = viewer;
	}
	
	
	public Node buildSceneRoot()
	{
		Group root = new Group();
		root.setName("root");
		
		Map map = new Map(10, 10.f);
		map.addBlock(4, 5);
		map.addBlock(6, 5);
		
		root.addChild(map.getGraph());
		
		// Add lights
		LightStore.getInstance().createLight("FixedLight0");
		LightStore.getInstance().setLightPositionDirection("FixedLight0", new Vector3f(1.7f, 7.f, 5.f));
		LightStore.getInstance().setLightColor("FixedLight0", new Vector3f(0.8f, 0.2f, 0.2f));
				
		LightStore.getInstance().createLight("FixedLight1");
		LightStore.getInstance().setLightPositionDirection("FixedLight1", new Vector3f(8.3f, 7.f, 5.f));
		LightStore.getInstance().setLightColor("FixedLight1", new Vector3f(0.2f, 0.8f, 0.2f));
		
		LightStore.getInstance().createLight("MobileLight");
		LightStore.getInstance().setLightPositionDirection("MobileLight", new Vector3f(5.f, 1.f, 20.f));
		LightStore.getInstance().setLightColor("MobileLight", new Vector3f(0.5f, 0.5f, 0.5f));
		
		Lights lights = new Lights();
		lights.addLight("FixedLight0");
		lights.addLight("FixedLight1");
		lights.addLight("MobileLight");
		
		lights.setNodeCallback(new LightCallback());
		
		lights.addChild(root);
		
		return lights;
	}

	
	public Vector3f getInitialCameraPos()
	{
		return new Vector3f(5.f, 10.f, 40.f);
	}

	
	public Quat4f getInitialCameraOrientation()
	{
		return new Quat4f(0.f, 0.f, 0.f, 1.f);
	}

	
	public void atExit()
	{
		// clear example resources
		_viewer.unloadResources();
	}

	
	public void atStart()
	{
		// Load example texture resources
		Resources.instance().addTextureToLoad(stone_wall, true);
		Resources.instance().addTextureToLoad(floor, true);
		_viewer.loadResources();
	}

}
